package com.pl.service.impl;  

import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.pl.bean.ManageRolePageBean;
import com.pl.dao.ManageRolePageBeanDao;
import com.pl.service.ManageRolePageService;
import com.pl.util.CommonUtil;

import javax.annotation.Resource;

/**
 * 
 */
@Service("manageRolePageService")
public class ManageRolePageServiceImpl implements ManageRolePageService{

	private static Logger log = LogManager.getLogger();

	@Resource(name="manageRolePageBeanDao")
	private ManageRolePageBeanDao manageRolePageBeanDao;

	/**
	 * 新增
	 */
	@Transactional
	public void addManageRolePage(ManageRolePageBean manageRolePageBean){
		
		manageRolePageBeanDao.addManageRolePageBean(manageRolePageBean);
	}
	
	/**
	 * 新增
	 */
	@Transactional
	public void addManageRolePage(long roleId, List<Long> pageIdList, long operateId){
		
		//删除旧数据
		manageRolePageBeanDao.deletePageByRole(roleId);
		
		if(pageIdList !=null && !pageIdList.isEmpty()){
			for (Long pageId : pageIdList) {
				
				ManageRolePageBean bean = new ManageRolePageBean();
				
				bean.setManage_role_id(roleId);
				bean.setManage_page_id(pageId);
				bean.setOperate_id(operateId);
				
				manageRolePageBeanDao.addManageRolePageBean(bean);
			}
		}
	}

	/**
	 * 修改
	 */
	@Transactional
	public void updateManageRolePage(ManageRolePageBean manageRolePageBean){
		
		manageRolePageBeanDao.updateManageRolePageBean(manageRolePageBean);
	}
	
	/**
	 * 根据条件获得数量
	 */
	public int getManageRolePageNum(ManageRolePageBean manageRolePageBean){
		
		return manageRolePageBeanDao.getManageRolePageBeanNum(manageRolePageBean);
	}
	
	/**
	 * 根据条件获得数据
	 */
	public List<ManageRolePageBean> getManageRolePage(ManageRolePageBean manageRolePageBean){
		
		return manageRolePageBeanDao.getManageRolePageBean(manageRolePageBean);
	}
	
	/**
	 * 根据条件获得数据
	 */
	public ManageRolePageBean getManageRolePageById(Long id){
		
		ManageRolePageBean manageRolePageBean = new ManageRolePageBean();
		manageRolePageBean.setId(id);
		
		List<ManageRolePageBean> list = getManageRolePage(manageRolePageBean);
		if(list !=null && !list.isEmpty()){
    		return list.get(0);
    	}
    	
    	return null;
	}
}
